home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1997
/
MacHack 1997.toast
/
Hacks
/
Hacks ’96
/
O Boy
/
Source
/
events.c
< prev
next >
Wrap
Text File
|
1996-06-21
|
9KB
|
431 lines
//
// events.h ... part of the shell from C.Spathis - TY Gus
//
#include <AppleEvents.h>
#include <AERegistry.h>
#include <EPPC.h>
#include <quickdraw.h>
#include <PictUtil.h>
#include <Drag.h>
#include "O Boy.h"
#include "Helpers_ut.h"
#include "debug.h"
#include "OBoy_hi.h"
#define kEndOfList nil // Nil terminator for variable argument list.
//#define topLeft(r) (((Point*)&(r))[0])
//#define botRight(r) (((Point*)&(r))[1])
// Drag Manager Crap
void DoStartDrag(CWindowPtr window, EventRecord *event);
pascal OSErr BogusSendProc(FlavorType theType, void *dragSendRefCon,
ItemReference theItemRef, DragReference theDragRef);
OSErr DoMakeHFSPromise(DragReference dragRefNum, ItemReference itemRefNum);
void OutlineRegion(RgnHandle theRgn);
OSErr GetDropLocationDirectory(AEDesc *dropLocation, long *directoryID, short *volumeID);
void HandleContentClick(CWindowPtr theWin,EventPtr theEvent);
void HandleNullEvent(EventPtr theEvent);
void HandleMouseDownEvent(EventPtr theEvent);
void HandleMouseUpEvent(EventPtr theEvent);
void HandleKeyDownEvent(EventPtr theEvent);
void HandleKeyUpEvent(EventPtr theEvent);
void HandleAutoKeyEvent(EventPtr theEvent);
void HandleUpdateEvent(EventPtr theEvent);
void HandleDiskEvent(EventPtr theEvent);
void HandleActivateEvent(EventPtr theEvent);
void HandleOSEvent(EventPtr theEvent);
void HandleHiLevelEvent(EventPtr theEvent);
void MenuHandler(EventPtr theEvent,short theMenu,short theItem);
void HandleFileMenu(EventPtr theEvent,short theItem);
Boolean gDone=FALSE;
Rect limitRect;
Rect sizeRect;
RGBColor white={65535,65535,65535},black={0,0,0};
void EventInit(void)
{
limitRect=qd.screenBits.bounds;
InsetRect(&limitRect,4,4);
sizeRect.top=312;
sizeRect.left=260;
sizeRect.bottom=qd.screenBits.bounds.bottom-qd.screenBits.bounds.top;
sizeRect.right=qd.screenBits.bounds.right-qd.screenBits.bounds.left;
}
Boolean DoEvents(void)
{
Boolean ret=FALSE;
Boolean wret;
EventRecord theEvent;
if (bHaveWaitNextEvent){
wret=WaitNextEvent(everyEvent,&theEvent,sleepTime,nil);
}else{
GetNextEvent(everyEvent,&theEvent);
SystemTask();
}
switch(theEvent.what){
case nullEvent:
HandleNullEvent(&theEvent);
break;
case mouseDown:
HandleMouseDownEvent(&theEvent);
break;
case mouseUp:
HandleMouseUpEvent(&theEvent);
break;
case keyDown:
HandleKeyDownEvent(&theEvent);
break;
case keyUp:
HandleKeyUpEvent(&theEvent);
break;
case autoKey:
HandleAutoKeyEvent(&theEvent);
break;
case updateEvt:
HandleUpdateEvent(&theEvent);
break;
case diskEvt:
HandleDiskEvent(&theEvent);
break;
case activateEvt:
HandleActivateEvent(&theEvent);
break;
case osEvt:
HandleOSEvent(&theEvent);
break;
case kHighLevelEvent:
HandleHiLevelEvent(&theEvent);
break;
default:
break;
}
ret=GetQuitStatus();
return ret;
}
void HandleNullEvent(EventPtr theEvent)
{
;
}
void HandleMouseDownEvent(EventPtr theEvent)
{
short where;
WindowPtr theWin;
Rect r,theRect;
GrafPtr savePort;
where=FindWindow(theEvent->where,&theWin);
switch(where){
case inDesk:
break;
case inMenuBar:
{
long theMenuItem;
short theMenu,theItem;
theMenuItem=MenuSelect(theEvent->where);
theMenu=HiWord(theMenuItem);
theItem=LoWord(theMenuItem);
if (theMenu!=0){
MenuHandler(theEvent,theMenu,theItem);
}
}
break;
case inSysWindow:
break;
case inContent:
if (theWin!=nil){
if (theWin!=FrontWindow()){
SelectWindow(theWin);
}else{
HandleContentClick((CWindowPtr)theWin,theEvent);
}
}
break;
case inDrag:
if (theWin!=nil){
if (theWin!=FrontWindow()){
SelectWindow(theWin);
}
DragWindow(theWin,theEvent->where,&limitRect);
if (theWin!=FrontWindow()){
SelectWindow(theWin);
// DrawGrowIcon(theWin);
}
}else{
SysBeep(10);
}
break;
case inGrow:
if (theWin!=nil){
long newWinSize;
GetPort(&savePort);
SetPort(theWin);
if (theWin!=FrontWindow()){
SelectWindow(theWin);
}
Rect theOldRect=((WindowPeek)theWin)->port.portRect;
newWinSize=GrowWindow(theWin,theEvent->where,&sizeRect);
if (newWinSize!=0){
theRect=((WindowPeek)theWin)->port.portRect;
SizeWindow(theWin,LoWord(newWinSize),HiWord(newWinSize),true);
SetRect(&r,theRect.left,theRect.bottom-15,theRect.right,theRect.bottom);
EraseRect(&r);
InvalRect(&r);
SetRect(&r,theRect.right-15,theRect.top,theRect.right,theRect.bottom);
EraseRect(&r);
InvalRect(&r);
// inform the hi
Rect theNewRect=((WindowPeek)theWin)->port.portRect;
OBoy_hi *theHI = (OBoy_hi *) GetWRefCon( (GrafPtr)theWin );
dassert( theHI != nil );
theHI->AdjustToSize( theOldRect, theNewRect );
}
SetPort(savePort);
}
break;
case inGoAway:
if (theWin!=nil){
if (theWin!=FrontWindow()){
SelectWindow(theWin);
}else if (TrackGoAway(theWin,theEvent->where)==TRUE){
OBoy_hi *theHI = (OBoy_hi *) GetWRefCon( (GrafPtr)theWin );
if( theHI != nil )
{
delete theHI;
}
}
}else{
SysBeep(10);
}
break;
case inZoomIn:
case inZoomOut:
if (theWin!=nil){
if (theWin!=FrontWindow()){
SelectWindow(theWin);
}else{
GrafPtr savePort;
GetPort(&savePort);
SetPort(theWin);
Rect theOldRect=((WindowPeek)theWin)->port.portRect;
ZoomWindow(theWin,where,true);
Rect theNewRect=((WindowPeek)theWin)->port.portRect;
OBoy_hi *theHI = (OBoy_hi *) GetWRefCon( (GrafPtr)theWin );
dassert( theHI != nil );
theHI->AdjustToSize( theOldRect, theNewRect );
SetPort(savePort);
}
}
default:
break;
}
}
void HandleContentClick(CWindowPtr theWin,EventPtr theEvent)
{
GrafPtr save_port;
GetPort( &save_port );
SetPort( (GrafPtr) theWin );
// oboy specific
OBoy_hi *theHI = (OBoy_hi *) GetWRefCon( (GrafPtr)theWin );
dassert( theHI != nil );
theHI->HandleClick( theEvent );
SetPort( save_port );
}
void HandleMouseUpEvent(EventPtr theEvent)
{
;
}
void HandleKeyDownEvent(EventPtr theEvent)
{
char theKey;
Boolean processed=false;
theKey=theEvent->message & charCodeMask;
if ( (theEvent->modifiers & cmdKey) !=0){
long menuResult;
short theMenu,theItem;
menuResult=MenuKey(theKey);
theMenu=HiWord(menuResult);
theItem=LoWord(menuResult);
if (theMenu!=0){
HiliteMenu(theMenu);
MenuHandler(theEvent,theMenu,theItem);
processed=true;
}
}
if (processed==false)
{
WindowPtr theWin=FrontWindow();
if( theWin != nil )
{
OBoy_hi *theHI = (OBoy_hi *) GetWRefCon( (GrafPtr)theWin );
if( theHI != nil )
{
theHI->HandleKeyDownEvent(*theEvent);
}
}
}
}
void HandleKeyUpEvent( EventPtr theEvent)
{
;
}
void HandleAutoKeyEvent( EventPtr theEvent)
{
;
}
void HandleUpdateEvent( EventPtr theEvent)
{
GrafPtr savePort;
WindowPtr theWin=(WindowPtr)theEvent->message;
Rect theRect=((WindowPeek)theWin)->port.portRect;
WinInfoHandle theH;
GetPort(&savePort);
SetPort(theWin);
BeginUpdate(theWin);
RGBForeColor(&black);
RGBBackColor(&OBoy_hi::_BackGroundGray);
EraseRect(&theRect);
if (theWin!=nil){
theH=(WinInfoHandle)((WindowPeek)theWin)->refCon;
OBoy_hi *theHI = (OBoy_hi *) GetWRefCon( theWin );
dassert( theHI != nil );
theHI->ReDraw( );
}
// DrawGrowIcon(theWin);
EndUpdate(theWin);
SetPort(savePort);
}
void HandleDiskEvent(EventPtr theEvent)
{
;
}
void HandleActivateEvent(EventPtr theEvent)
{
InitCursor();
Rect theRect;
WindowPtr theW=(WindowPtr)theEvent->message;
if( theW != nil )
{
SetRect( &theRect,theW->portRect.right-15,
theW->portRect.bottom-15,
theW->portRect.right,
theW->portRect.bottom );
StPort thePort( theW );
InvalRect( &theRect );
}
}
void HandleOSEvent(EventPtr theEvent)
{
if (theEvent->message & 0x01000000){
if (theEvent->message & 0x00000001){
WindowPtr theW=FrontWindow();
if (theW!=nil){
//DrawGrowIcon(theW); // Activate Event
}
}else{
; // Deactivate Event
}
}
if ((theEvent->message&0xFF000000)==0xFA000000){
; // Cursor Maintenance
}
}
void HandleHiLevelEvent(EventPtr theEvent)
{
AEProcessAppleEvent(theEvent); // Let the Apple Event Manager handle high level event.
}
void MenuHandler(EventPtr theEvent,short theMenu,short theItem)
{
Str255 daName;
GrafPtr savePort;
switch(theMenu){
case APPLE_MENU:
switch(theItem){
case 1:
OBoy_hi::ShowAbout();
break;
default:
GetPort(&savePort);
GetItem(GetMHandle(APPLE_MENU), theItem, daName);
OpenDeskAcc(daName);
SetPort(savePort);
break;
}
break;
case FILE_MENU:
HandleFileMenu(theEvent,theItem);
break;
default:
while(!Button());
break;
}
HiliteMenu(0);
}
void HandleFileMenu(EventPtr theEvent,short theItem)
{
switch(theItem){
case 1:
OBoy_hi *theHumanInterface = new OBoy_hi;
break;
case 3:
QuitApp();
break;
default:
break;
}
}
void QuitApp(void)
{
// dispose of the list handle
// WindowPtr theWindow = FrontWindow();
// OBoy_hi *theHI = (OBoy_hi *) GetWRefCon( (GrafPtr)theWindow );
// dassert( theHI != nil );
// delete theHI;
gDone=TRUE;
}
Boolean GetQuitStatus()
{
return gDone;
}